select c1,
floor(1 / (row_number() over (partition BY c1 order by c2))) as is_first_row
from t
select pk,
max(case when c1 = 1 then c2
else '#N/A'
end) as c3,
max(case when c1 = 2 then c2
else '#N/A'
end) as c4,
from t
group by pk
select c2
from t
union
select c1
from t
coalesce('u' + t1.pk1::varchar(255),'s' + t1.pk2::varchar(255),'a' + t1.pk3::varchar(255)) =
coalesce('u' + t2.pk1::varchar(255),'s' + t2.pk2::varchar(255),'a' + t2.pk3::varchar(255))
select pk,
count(1)
from t
group by pk
having count(1)>1
select EXTRACT('EPOCH' FROM c1)
from t
select *
from t1
left join t2
on t2.pk = t1.pk
whenere t2.pk is null
insert into t1_temp
from <query over t2>;
insert into t1
from <query over t3>;
insert into t1
from <query over t4>;
insert into t1
from t1_temp
group by pk1;
In [ ]:
```sql
create table t3_que as
select c1
from t1_fact
left join t2_dim
on t1_fact.pk = t2_dim.pk
where t2_dim is null
```
select REVERSE(SPLIT_PART(REVERSE(c1),'_',1))
from t
select c1,
c2
from t1
where ((date_part(dow, c1)=6 AND datediff(day, c1, c2)<=2) OR
(date_part(dow, c1)=0 AND datediff(day, c1, c2)<=1) OR
(date_part(dow, c1)=5 AND datediff(hour, c1, c2) <= 72) OR
(date_part(dow, c1) in (1,2,3,4) AND datediff(hour,c1, c2)<=24
select c1
c2 AS from_time,
isnull(LEAD(c2) OVER (PARTITION BY c1 ORDER BY c2 ), '2999-01-01') AS to_time
from t1
where event_name = 'x'
create temp table exploded as
select row_number() over (order by true) as day
from t1 limit 10;
select exploded.day as day,
count(distinct c1)
from t2
cross join exploded
where getdate() > t2.c2
and getdate()< DATEADD('day',t2.c2)
group by day
(select isnull(max(gk),0) from t) + row_number() over (order by 1) as gk
select * from table order by random() limit 1000;
select * from table where random() < 0.01;